@extends('shared.master')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb layout-title">
                <li><a href="{{url('project')}}">Project</a></li>
                <li class="active" ><i class="fa fa-suitcase fa-fw"></i> Input</li>
            </ol>
                {{PageData::Error()}}

                {{ Form::open(array('url' => '#')) }}
            <div class='row'>
            <div class="col-lg-6">
                <div class="form-group">
                    {{Form::label('name','Name *')}}
                    {{Form::hidden('id',$Model->getId())}}
                    {{Form::text('name',$Model->getName(),array('class'=>'form-control'))}}
                </div>
                <div class="form-group">
                    {{Form::label('description','Description *')}}
                    {{Form::text('description',$Model->getDescription(),array('class'=>'form-control'))}}
                </div>
                <div class="form-group">
                    {{Form::label('startdate','Start Date *')}}
                    {{Form::text('startdate',$Model->getStartDate()!=null ? date("d-m-Y",strtotime($Model->getStartDate())) : "",array('class'=>'form-control hasDatepicker' ))}}
                    <script>
                    $('#startdate').datepicker({
                        format: 'dd-mm-yyyy'
                    })
                    </script>
                </div>
				
                <div class="form-group">
                    {{Form::label('duedate','Due Date *')}}
                    {{Form::text('duedate',$Model->getDueDate()!=null ? date("d-m-Y",strtotime($Model->getDueDate())) : "",array('class'=>'form-control hasDatepicker'))}}
                    <script>
                    $('#duedate').datepicker({
                        format: 'dd-mm-yyyy'
                    })
                    </script>
                </div>
                <div class="form-group">
                    {{Form::label('createdby','Created By')}}<br>
                    {{$Model->getCreatedBy()!=null ? $Model->getCreatedBy()->getName() : "-"}}
                    {{Form::hidden('createdby',$Model->getCreatedBy()!=null ? $Model->getCreatedBy()->getName() : "",array('class'=>'form-control'))}}
                </div>
                <div class="form-group">
                    {{Form::label('createdat','Created Date')}} <br>
                    {{$Model->getCreatedDate()}}
                    {{Form::hidden('createdat',date("d-m-Y",strtotime($Model->getCreatedDate()!=null ? $Model->getCreatedDate() : date("d-m-Y"))),array('class'=>'form-control hasDatepicker'))}}
                </div>
                
            <br>
                <div class="panel panel-default">
                <div class="panel-heading">
                  <h3 class="panel-title">Project Employee Assignment</h3>
                </div>
                <table class="table table-striped table-bordered table-hover" id="tblDataUser">
                    <thead>
                        <tr>
                            <th>Employee Name</th>
                            <th width="36px"></th>
                        </tr>
                    </thead>
                </table>
                <div class="panel-footer">
                <button onClick="addRowTable('tblDataUser',null);" type="button" class="btn btn-primary">Add Row</button>
                </div>
            </div>
            <script>
                var input_table = new Array(); 
		function addRowData(data, table_id) { 
                    input_table[table_id].addRow(data, true, '../../public/images/delete.png'); 
		} 

                function addRowDataWithoutDelete(data, table_id) { 
                    input_table[table_id].addRow(data); 
		} 

		function removeRow(id, table_id) { 
                    input_table[table_id].removeRow(id); 
		} 
		
		function addRowTable(table_id, obj_data) { 
                    eval('addRow' + table_id + '(table_id, obj_data);'); 
		} 

                input_table['tblDataUser'] = new azTable('tblDataUser'); 
		var cnttblDataUser = 0; 
                
                <?php 
                    $comboEmployee = '<select class="form-control" id="projectProjectAssignmentUserId_\' + cnttblDataUser + \'" name="projectProjectAssignmentUserId[]">';
                    foreach($EmployeeCombo as $key=>$item){
                                $comboEmployee .= '<option value="'.$key.'">'.$item.'</option>';
                            }
                    $comboEmployee .= '</select>';
                ?>
                    
                    
                    
                function addRowtblDataUser(table_id, obj_data) { 
                    if(obj_data == null) { 
                            obj_data = {
                                Id: '',
                                projectId: '',
                                userId: ''
                            } 

                    } 
			
                    val_Id = (obj_data.Id == undefined) ? '' : obj_data.Id;
                    val_projectId = (obj_data.projectId == undefined) ? '' : obj_data.projectId;
                    val_userId = (obj_data.userId == undefined) ? '' : obj_data.userId;
                    
                    cnttblDataUser++; 
                    
                    addRowData([ 
                        "<input type='hidden' id='projectProjectAssignment_" + cnttblDataUser + "' name='projectProjectAssignment[]'  value='" + cnttblDataUser  + "' />" +
                        "<input type='hidden' id='projectProjectAssignmentId_" + cnttblDataUser + "' name='projectProjectAssignmentId[]'  value='" + val_Id  + "' />" +
                        "<input type='hidden' id='projectProjectAssignmentprojectId_" + cnttblDataUser + "' name='projectProjectAssignmentprojectId[]' value='" + val_projectId + "'>" +
                        '{{$comboEmployee}}'
                        ], 
                    table_id);
                    selectDefaultCombo('projectProjectAssignmentUserId_' + cnttblDataUser , val_userId);
                }
                @if($Model->getProjectAssignment() != null)
                    @foreach ($Model->getProjectAssignment() as $item)
                    obj_data = {
                        Id: '{{$item->getId()}}',
                        projectId: '{{$item->getProject()!=null ? $item->getProject()->getId() : "-"}}',
                        userId: '{{$item->getUser()!=null ? $item->getUser()->getId() : "-"}}'
                    } 
                    addRowTable('tblDataUser',obj_data);
                    @endforeach
                @endif
            </script>
                
            </div>
            </div>
            <br>
            
            
                <div class="panel panel-default">
                <div class="panel-heading">
                  <h3 class="panel-title">Task Assignment</h3>
                </div>
                <table class="table table-striped table-bordered table-hover" id="tblDataTask">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Start Date</th>
                            <th>Due Date</th>
                            <th>Priority</th>
                            <th>Notes</th>
                            <th width="36px"></th>
                        </tr>
                    </thead>
                </table>
                <div class="panel-footer">
                <button onClick="addRowTable('tblDataTask',null);" type="button" class="btn btn-primary">Add Row</button>
                </div>
            </div>
            <script>
                input_table['tblDataTask'] = new azTable('tblDataTask'); 
		var cnttblDataTask = 0; 
                
                <?php 
                    $comboPriority = '<select class="form-control" id="projectTaskPriorityId_\' + cnttblDataTask + \'" name="projectTaskPriorityId[]">';
                    foreach($PriorityCombo as $key=>$item){
                                $comboPriority .= '<option value="'.$key.'">'.$item.'</option>';
                            }
                    $comboPriority .= '</select>';
                ?>
                    
                function addRowtblDataTask(table_id, obj_data) { 
                    if(obj_data == null) { 
                            obj_data = {
                                Id: '',
                                name: '',
                                startDate: '',
                                dueDate: '',
                                priorityId: '',
                                statusId: '',
                                projectId: '',
                                notes: ''
                            } 

                    } 
			
                    val_Id = (obj_data.Id == undefined) ? '' : obj_data.Id;
                    val_name = (obj_data.name == undefined) ? '' : obj_data.name;
                    val_startDate = (obj_data.startDate == undefined) ? '' : obj_data.startDate;
                    val_dueDate = (obj_data.dueDate == undefined) ? '' : obj_data.dueDate;
                    val_priorityId = (obj_data.priorityId == undefined) ? '' : obj_data.priorityId;
                    val_statusId = (obj_data.statusId == undefined) ? '' : obj_data.statusId;
                    val_projectId = (obj_data.projectId == undefined) ? '' : obj_data.projectId;
                    val_notes = (obj_data.notes == undefined) ? '' : obj_data.notes;
                    
                    cnttblDataUser++; 
                    if(val_statusId!="open"){
                        addRowDataWithoutDelete([ 
                        "<input type='hidden' id='projectTask_" + cnttblDataTask + "' name='projectTask[]'  value='" + cnttblDataUser  + "' />" +
                        "<input type='hidden' id='projectTaskId_" + cnttblDataTask + "' name='projectTaskId[]'  value='" + val_Id  + "' />" +
                        "<input type='hidden' id='projectTaskProjectId_" + cnttblDataTask + "' name='projectTaskProjectId[]' value='" + val_projectId + "'>" +
                        "<input type='hidden' id='projectTaskStatusId_" + cnttblDataTask + "' name='projectTaskStatusId[]' value='" + val_statusId + "'>" +
                        "<input type='text' id='projectTaskName_" + cnttblDataTask + "' class='form-control' name='projectTaskName[]' value='" + val_name + "'>",
                        "<input type='text' id='projectTaskStartDate_" + cnttblDataTask + "' class='form-control' name='projectTaskStartDate[]' value='" + val_startDate + "'>",
                        "<input type='text' id='projectTaskDueDate_" + cnttblDataTask + "' class='form-control' name='projectTaskDueDate[]' value='" + val_dueDate + "'>",
                        '{{$comboPriority}}',
                        "<textarea id='projectTaskNotes_" + cnttblDataTask + "' class='form-control' name='projectTaskNotes[]' value='" + val_name + "'>" + val_notes + "</textarea>"
                        ], 
                    table_id)
                    }else{
                        addRowData([ 
                        "<input type='hidden' id='projectTask_" + cnttblDataTask + "' name='projectTask[]'  value='" + cnttblDataUser  + "' />" +
                        "<input type='hidden' id='projectTaskId_" + cnttblDataTask + "' name='projectTaskId[]'  value='" + val_Id  + "' />" +
                        "<input type='hidden' id='projectTaskProjectId_" + cnttblDataTask + "' name='projectTaskProjectId[]' value='" + val_projectId + "'>" +
                        "<input type='hidden' id='projectTaskStatusId_" + cnttblDataTask + "' name='projectTaskStatusId[]' value='" + val_statusId + "'>" +
                        "<input type='text' id='projectTaskName_" + cnttblDataTask + "' class='form-control' name='projectTaskName[]' value='" + val_name + "'>",
                        "<input type='text' id='projectTaskStartDate_" + cnttblDataTask + "' class='form-control' name='projectTaskStartDate[]' value='" + val_startDate + "'>",
                        "<input type='text' id='projectTaskDueDate_" + cnttblDataTask + "' class='form-control' name='projectTaskDueDate[]' value='" + val_dueDate + "'>",
                        '{{$comboPriority}}',
                        "<textarea id='projectTaskNotes_" + cnttblDataTask + "' class='form-control' name='projectTaskNotes[]' value='" + val_name + "'>" + val_notes + "</textarea>"
                        ], 
                    table_id); 
                    }
                    
                    selectDefaultCombo('projectTaskPriorityId_' + cnttblDataTask , val_priorityId);
                    
                    $("#projectTaskStartDate_" + cnttblDataTask).datepicker({
                        format: 'dd-mm-yyyy'
                    })
                    
                    $("#projectTaskDueDate_" + cnttblDataTask).datepicker({
                        format: 'dd-mm-yyyy'
                    })
                    
                } 	
                @if($Model->getTasks()!=null)
                    @foreach ($Model->getTasks() as $item)
                    obj_data = {
                        Id: '{{$item->getId()}}',
                        name: '{{$item->getName()}}',
                        startDate: '{{$item->getStartDate()!=null ? date("d-m-Y",strtotime($item->getStartDate())) : ""}}',
                        dueDate: '{{$item->getDueDate()!=null ? date("d-m-Y",strtotime($item->getDueDate())) : ""}}',
                        priorityId: '{{$item->getPriority()!=null ? $item->getPriority()->getId() : "-"}}',
                        statusId: '{{$item->getStatus()!=null ? $item->getStatus()->getId() : "-"}}',
                        projectId: '{{$item->getProject()!=null ? $item->getProject()->getId() : "-"}}',
                        notes: '{{$item->getNotes()}}'
                    } 
                    addRowTable('tblDataTask',obj_data);
                    @endforeach
                @endif
            </script>
            
                <p>
                    {{Form::submit('Save',array('class'=>'btn btn-primary',"name"=>"submit"))}}
                    {{Form::button('Close',array('class'=>'btn btn-primary','onClick'=>"location.href='".url('project')."'"))}}
                </p>
                {{ Form::close() }}
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>
<!-- /.container-fluid -->
    <script>
    
    </script>
@stop